import JSEncrypt from 'jsencrypt/bin/jsencrypt'

// 密钥对生成 http://web.chacuo.net/netrsakeypair
// 不需要输入密码512
const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJ78JUKwUT0jTbYbhs76UdXuEt7GlmNE\n' +
  'NvCt98JL8k0iE3KUZZtCVMIVYAdrUCQfNF36Sxc+48z5xmUE+C3gwYsCAwEAAQ=='

const privateKey = 'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAnvwlQrBRPSNNthuG\n' +
  'zvpR1e4S3saWY0Q28K33wkvyTSITcpRlm0JUwhVgB2tQJB80XfpLFz7jzPnGZQT4\n' +
  'LeDBiwIDAQABAkBSLxm7zZVRO2yylKwtVmzzX6xViOa4zcxwwh1vTP8mK4ShcTX8\n' +
  'bPkyHzkby7TJRwWl2qDoWh4ra2t8oHAEmP3RAiEA0ANvMrELeFVwarisp2F5gTHi\n' +
  'NmCngEy5n0Rw4FCBKQ8CIQDDqUGV5J1/I2sgW2NjGMsJiWZkGD6BPzjkSCj/TFdH\n' +
  'xQIgHlSh3i5akc1Deww6gJ2B7gisB2nIgritSD/ehZa3fpkCIF/vr67VZ7wdG7vD\n' +
  '05mVYIiOjFvr30n0O+sCzsdPIUSZAiEAtn5gIvpKIrc/EF6gREczWPTsIgrrl/jo\n' +
  'JhQECWxlzU0='

// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对需要加密的数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey)
  return encryptor.decrypt(txt)
}

